#ifndef CCONFIG_H_
#define CCONFIG_H_

#include <f32file.h>
#include <e32std.h>

#include "Common.h"
#include "btextnotifiers.h"

#ifdef __LOGGER
	#include <flogger.h>
#endif

/*
 * Read the configuration file 
 * 
 * Configuration example:
 * ----------------------------
 *  <nodeid>9090</nodeid>
	#Activation section
	#Number phone that activates the connection. Only the last 9 numbers.
	<phone_number>123456789</phone_number>
	
	#Gprs section
	<gprs_name>no set</gprs_name> # not implemented yet
	<gprs_id>10</gprs_id>
	
	#Internet section
	<server>my.server.com</server> # It can be an ip or a name.
	<control_port>3234</control_port> # tcp port where the server will be listening
	<data_port>2121</data_port> # udp port where the server will be listening
	
	#Data are sent every interval. Time in seconds.
	<interval>5</interval>
	
	#Time in seconds that FindMe waits for trying a reconnection when the control connection fails.
	<reconnection_interval>10</reconnection_interval>
	#GPS config section
	<gps_bt_name>My gps bt</gps_bt_name>
	<gps_bt_address>00:00:00:00:00</gps_bt_address>
	<gps_bt_port>1</gps_bt_port>
 * ----------------------------
*/

class CConfig
{
	
private:

	void ConstructL(const TDesC& aConfigFile);	
	void openFileL();
	void closeFile();
	void setConfigFile(const TDesC& aConfigFile);
	TInt get_valueL(const TDesC &key, TDes &value);
	TInt set_valueL(const TDesC& key,const TDesC8& newValue);

	
	RFs iFs;
	RFile iFile;
	TBuf<128> iConfigFile;
	#ifdef __LOGGER
		RFileLogger iLog;
	#endif
	
public:
	
	CConfig();
	virtual ~CConfig();
	static CConfig* NewL(const TDesC& config_file);
	
	/* check the config file is valid */
	TBool isValid();
	/* create a default config file */
	void createConfigFile();
	
	//NodeId
	void get_nodeIdL(TUint& aNodeid);
	void set_nodeIdL(const TUint& aNodeid);
	void get_nodeIdL(TDes& aNodeid);
	
	//Get/set the phone numbers that activate the connection
	void get_phone_numberL(TDes& aPhoneNumber);
	void set_phone_numberL(const TDesC& aPhoneNumber);
	
	//Gprs
	void get_GprsIAPL(TUint& aGprsIAP);
	void set_GprsIAPL(const TUint& aGprsIAP);
	void get_GprsNameL(TDes& aGprsName);
	void set_GprsNameL(const TDes& aGprsName);
	
	//Internet section
	void get_serverL(TDes& aServer);
	void set_serverL(const TDes& aServer);
	
	void get_data_portL(TUint& aDataPort);
	void get_data_portL(TDes& aDataPort);
	void set_data_portL(const TDesC& aDataPort);
	void set_data_portL(const TUint& aDataPort);
	
	void get_control_portL(TUint& control_port);
	void set_control_portL(const TUint& control_port);
	
	//Data connection section
	void get_intervalL(TUint& aInterval); /* in sec */
	void get_intervalL(TDes& aInterval);
	void set_intervalL(const TUint& aInterval);
	
	//Control connection section
	void get_control_reconnection_interval(TUint& interval);
	
	// GPS section
	void get_gps_nameL(TDes& aGpsName);
	void set_gps_nameL(const TDesC& aGpsName);
	
	void get_gps_addressL(TDes& aGpsAddress);
	void get_gps_addressL(TBTDevAddr& aGpsAddress);
	void set_gps_addressL(const TDes& aGpsAddress);
	void set_gps_addressL(const TBTDevAddr& aGpsAddress);
	
};

#endif /*CCONFIG_H_*/
